package com.kgd.news.controller.admin;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.kgd.news.entity.Comment;
import com.kgd.news.utils.BaseController;
import com.kgd.news.utils.StringUtilsWx;

/**
 * @Email: huangsanm@foxmail.com
 * @Date: 2017/10/10
 * @Time: 下午4:10
 */
public class CommentController extends BaseController {


    @Override
    public void list() {
        String sstime = getPara("s_time");
        String estime = getPara("e_time");
        String content = getPara("content");
        String otherid = getPara("otherid");
        String sql = "from comment where 1=1 ";
        String type = "comment";
        if (!StringUtilsWx.isEmpty(estime)) {
            sql += " and creattime <= DATE_FORMAT(" + estime + ", '%Y-%m-%d %H:%i')";
        }
        if (!StringUtilsWx.isEmpty(sstime)) {
            sql += " and creattime <= DATE_FORMAT(" + sstime + ", '%Y-%m-%d %H:%i')";
        }
        if (!StringUtilsWx.isEmpty(content)) {
            sql += " and content like '%" + content + "%'";
            type += content;

        }
        if (!StringUtilsWx.isEmpty(otherid)) {
            sql += " and otherid = " + otherid;
            type += otherid;
        }
        sql += " order by id desc";
        Page<Comment> data = Comment.dao.paginate(getPageIndex(type), PAGE_SIZE, "select *", sql);
        setAttr("data", data);
        setAttr("otherid", otherid);
        render("comment_list.html");
    }

    @Override
    public void edit() {

    }

    @Override
    public void save() {

    }

    @Override
    public void del() {
        String ids = getPara("ids");
        Db.update("delete from comment where id in (" + ids + ")");

        list();
    }
}
